/*****************************************************
 *
 * main.c
 *
 * Description : Hello World in C, ANSI-style
 *
 */

#include "Os.h"
#include "Can.h"
#include "CanIf.h"
#include "Port.h"
#include "ComM.h"
#include "CanSm.h"
#include "Xcp.h"

int main(void)
{
	TickType tick10ms = 0;
    TickType remainTime = 10;

	InitSystem();
	Port_Init(NULL_PTR);
	Can_Init(NULL_PTR);
	CanIf_Init(NULL_PTR );
	ComM_Init();
	CanSM_Init();
	Xcp_Init(&XcpConfig);
	__enable();

	ComM_RequestComMode(0,COMM_FULL_COMMUNICATION);

	(void)GetCounterValue(0, &tick10ms);

    while(1)
    {
    	TickType elapsedtime;

    	GetElapsedCounterValue(0, &tick10ms, &elapsedtime);

    	if (elapsedtime >= remainTime)
    	{
    		remainTime = 10;
    	    ComM_MainFunction_00();
    	    CanSM_MainFunction();
    	    Xcp_MainFunction();
    	    Xcp_EventIndication(EventChannel_0);
    	}
    	else
    	{
    		remainTime = remainTime - elapsedtime;
    	}

    	Can_MainFunction_BusOff();
    	Can_MainFunction_Read();
    	Can_MainFunction_Write();
    } /* loop forever */
}


